<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org"
>
<head>
    <meta charset="UTF-8">
    <title>角色管理</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <script th:inline="javascript" type="text/javascript" rel="script" src="../axios/axios.min.js"></script>
    <script th:inline="javascript" type="text/javascript" rel="script" src="../axios/qs.js"></script>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/heyui/themes/index.css"></link>
    <script th:inline="javascript" type="text/javascript" rel="script" src="../axios/ajax.js"></script>
</head>
<body>

<div id="app1" v-padding="20">
    <div class="h-panel">
    <div class="h-panel-bar">
        <span class="h-panel-title">角色添加</span>
        <span v-color:gray v-font="13"></span>
    </div>
    <div class="h-panel-bar">
        <div class="h-btn-group">
            <button class="h-btn" @click="submit"><i class="h-icon-inbox"></i><span>保存</span></button>
            <button class="h-btn"><i class="h-icon-trash"></i><span>取消</span></button>
        </div>
    </div>
    <div class="h-panel-body bottom-line">
        <h-form ref="form" :label-width="150" :rules="rules" :model="data">
            <h-form-item label="角色名称" prop="roleName">
                <input type="text" v-model="data.roleName" />
            </h-form-item>
            <h-formitem label="角色类型" prop="roleType">
                <h-select v-model="data.roleType" :datas="roleTypes" placeholder="请选择角色类型" null-option-text="请选择角色类型"></h-select>
            </h-formitem>
            <h-form-item label="数据对象" prop="dataObject">
                <input type="text" v-model="data.dataObject" />
            </h-form-item>
            <h-form-item label="描述" prop="description">
                <input type="text" v-model="data.description" />
            </h-form-item>
        </h-form>
    </div>
</div>
</div>
<script>
    var app = new Vue({
        el: '#app1',
        data() {
            return {
                labelPosition: "left",
                data: {

                },
                roleTypes: [],
                rules: {
                    required: ['roleName','roleType']
                },
                isLoading: false,
            }
        },
        methods: {
            submit(){
                axios({
                    url:'saverole',
                    method:'post',
                    headers: {'Content-Type': 'application/x-www-form-urlencoded'},
                    data: Qs.stringify(this.data)
                }).then(responese => {
                    if (responese.status == 200) {
                        const d = responese.data;
                        console.log(d)
                        if (d.success) {
                            alert(d.data);
                        } else {
                            alert(d.error)
                        }

                    }
                });
            },
        },
        components: {
        },
        mounted(){
            axios.get('../dict/getdatabytype/roleType').then(response => {
                if (response.status == 200) {
                    const data = response.data.data;
                    for (let d of data) {
                        const obj = {'key':d.value,'title':d.label};
                        this.roleTypes.push(obj)
                    }
                }
            });
        }

    })
</script>

<script th:inline="javascript" src="https://cdn.jsdelivr.net/npm/vue"></script>
<script th:inline="javascript" src="https://cdn.jsdelivr.net/npm/heyui"></script>
</body>
</html>